#include "graphics/d3d/ood3d9render.h"
#include "graphics/oodisplaywindow.h"

//------------------------------------------------------------------------
ooD3D9Render::ooD3D9Render()
:m_windowed(false)
,m_setup(false)
,m_focus(DBBNULL)
,m_d3d(DBBNULL)
,m_device(DBBNULL)
{
	_init();
}

//------------------------------------------------------------------------
ooD3D9Render::~ooD3D9Render()
{

}

//------------------------------------------------------------------------
void
ooD3D9Render::focusWindow(ooDisplayWindow* window)
{
	m_focus = window;
}

//-------------------------------------------------------------------------
void
ooD3D9Render::setupRender()
{
	dbbassert(DBBNULL!=m_focus);
	D3DDISPLAYMODE d3ddm;
	m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);
	D3DFORMAT format				= d3ddm.Format;
	ZeroMemory(&m_params,sizeof(m_params));
	m_params.BackBufferFormat		= format;
	m_params.hDeviceWindow			= m_focus?(HWND)(m_focus->getWindowHandle()):NULL;
	m_params.SwapEffect				= D3DSWAPEFFECT_DISCARD;
	m_params.PresentationInterval	= D3DPRESENT_INTERVAL_IMMEDIATE;
	m_params.Windowed				= m_windowed;
	//paras.EnableAutoDepthStencil  = TRUE;
	//paras.AutoDepthStencilFormat  = D3DFMT_D16;

	if (!m_windowed)
	{
		m_params.BackBufferWidth			= m_focus->getWidth();
		m_params.BackBufferHeight			= m_focus->getHeight();
		m_params.BackBufferCount			= 1;
		m_params.MultiSampleType			= D3DMULTISAMPLE_NONE;
		m_params.FullScreen_RefreshRateInHz	= D3DPRESENT_RATE_DEFAULT;
	}
	dbbcheck(SUCCEEDED(m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, (HWND)(m_focus->getWindowHandle()), D3DCREATE_SOFTWARE_VERTEXPROCESSING, &m_params, &m_device)))
}

//------------------------------------------------------------------------
void 
ooD3D9Render::tick( float elasped )
{

}

//------------------------------------------------------------------------
void
ooD3D9Render::beginFrame()
{
	dbbtodo
}

//------------------------------------------------------------------------
void
ooD3D9Render::endFrame()
{
	dbbtodo
}

//------------------------------------------------------------------------
void 
ooD3D9Render::drawImage( const ooImage* image )
{

}

//------------------------------------------------------------------------
LPDIRECT3DDEVICE9
ooD3D9Render::getDevice() const
{
	return m_device;
}

//------------------------------------------------------------------------
void
ooD3D9Render::_init()
{
	m_d3d	= Direct3DCreate9(D3D_SDK_VERSION);
	dbbassert(NULL!=m_d3d);
}
